

#import "Adapter.h"

@implementation Adapter
//比例
+ (CGFloat)ratio
{
    
    return [UIScreen mainScreen].bounds.size.width / 375.f;
}

+ (CGFloat)valueWithValue:(CGFloat)value
{
    return value * [Adapter ratio];
}

+(CGFloat)ratioForHeight
{
   
    return [UIScreen mainScreen].bounds.size.height / IPHONE6_SIZE.height;
}

//+ (CGRect)frameFromSizeOfIphone6:(CGRect)frame
//{
//    return CGRectMake([Adapter valueWithValue:frame.origin.x], frame.origin.y, [Adapter valueWithValue:frame.size.width], frame.size.height);
//}
+ (CGRect)frameFromSizeOfIphone6:(CGRect)frame
{
    return CGRectMake([Adapter valueWithValue:frame.origin.x], [Adapter valueWithValue:frame.origin.y], [Adapter valueWithValue:frame.size.width], [Adapter valueWithValue:frame.size.height]);
}


+ (CGPoint)pointFromSizeIphone6:(CGPoint)point
{
    return CGPointMake([Adapter valueWithValue:point.x], [Adapter valueWithValue:point.y]);
}

+ (CGFloat)naRatioForHeight{
     return ([UIScreen mainScreen].bounds.size.height-64) / (IPHONE6_SIZE.height-64);
}
//
+(void)adapteFrame:(UIView *)view
{
//    view.layer.borderWidth = [Adapter ratio]*view.layer.borderWidth;
    view.layer.cornerRadius = Adapter(view.layer.cornerRadius);
    view.frame = [Adapter frameFromSizeOfIphone6:view.frame];
    [Adapter adapteFrameForSubView:view];
}

+ (void)adapteFrameForSubView:(UIView *)view
{
    for (UIView *subview in view.subviews) {
//        subview.layer.borderWidth = [Adapter ratio]*subview.layer.borderWidth;
       
        if ([subview isKindOfClass:[UIImageView class]]) {
            if(subview.tag==252){//表示大小不变 多用于小icon
                continue;
            }else{
                 subview.layer.cornerRadius = Adapter(subview.layer.cornerRadius);
            }

            if (subview.tag != 251) {//不变形  251表示可以根据屏幕压缩变形
               
                subview.frame = CGRectMake(subview.frame.origin.x*[Adapter ratio], subview.frame.origin.y, subview.frame.size.width*[Adapter ratio], subview.frame.size.height*[Adapter ratioForHeight]);
                continue;
            }
        }else{
             subview.layer.cornerRadius = Adapter(subview.layer.cornerRadius);
        }
        subview.frame = [Adapter frameFromSizeOfIphone6:subview.frame];
        
//        [subview setAutoresizesSubviews:YES];
//        
//        if ([subview isKindOfClass:[UILabel class]]) {
//            ((UILabel *)subview).font = [UIFont fontWithName:((UILabel *)subview).font.familyName size:[Adapter ratio]*((UILabel *)subview).font.pointSize];
//           
//        }
//        
//        if ([subview isKindOfClass:[UIButton class]]) {
//            ((UIButton *)subview).titleLabel.font = [UIFont fontWithName:((UIButton *)subview).titleLabel.font.familyName size:[Adapter ratio]*((UIButton *)subview).titleLabel.font.pointSize];
////            [((UIButton *)subview).titleLabel setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
//        }
//
//        if ([subview isKindOfClass:[UITextField class]]) {
//            ((UITextField *)subview).font = [UIFont fontWithName:((UITextField *)subview).font.familyName size:[Adapter ratio]*((UITextField *)subview).font.pointSize];
//            
//        }
//        
//        if ([subview isKindOfClass:[UITextView class]]) {
//            ((UITextView *)subview).font = [UIFont fontWithName:((UITextView *)subview).font.familyName size:[Adapter ratio]*((UITextView *)subview).font.pointSize];
//        }
//        
     //2016-06-27 11:24:46.763 车信帮3.0[641:260266] 当前的约束是{{87, 302}, {146, 30}}
        //{{87, 400}, {201, 30}}
        
        if (subview.subviews.count>0&&![subview isKindOfClass:[UIButton class]]) {
            [Adapter adapteFrameForSubView:subview];
        }
//        if (subview.subviews.count>0) {
//            [Adapter adapteFrameForSubView:subview];
//        }
      
    }
}

+ (void)adapteNavgationFrame:(UIView *)view{
    view.layer.borderWidth = [Adapter ratio]*view.layer.borderWidth;
    view.frame = [Adapter frameNavFromSizeOfIphone6:view.frame];
    [Adapter adapteFrameForNavaSubView:view];
}

+ (CGRect)frameNavFromSizeOfIphone6:(CGRect)frame
{
    return CGRectMake([Adapter valueWithValue:frame.origin.x], frame.origin.y, [Adapter valueWithValue:frame.size.width], frame.size.height);
}

+ (void)adapteFrameForNavaSubView:(UIView *)view
{
    for (UIView *subview in view.subviews) {
        
        subview.frame = [Adapter frameNavFromSizeOfIphone6:subview.frame];
        
//        if ([subview isKindOfClass:[UILabel class]]) {
//            ((UILabel *)subview).font = [UIFont fontWithName:((UILabel *)subview).font.familyName size:[Adapter ratio]*((UILabel *)subview).font.pointSize];
//        }
//        
//        if ([subview isKindOfClass:[UIButton class]]) {
//            ((UIButton *)subview).titleLabel.font = [UIFont fontWithName:((UIButton *)subview).titleLabel.font.familyName size:[Adapter ratio]*((UIButton *)subview).titleLabel.font.pointSize];
//        }
//        
//        if ([subview isKindOfClass:[UITextField class]]) {
//            ((UITextField *)subview).font = [UIFont fontWithName:((UITextField *)subview).font.familyName size:[Adapter ratio]*((UITextField *)subview).font.pointSize];
//        }
//        
//        if ([subview isKindOfClass:[UITextView class]]) {
//            ((UITextView *)subview).font = [UIFont fontWithName:((UITextView *)subview).font.familyName size:[Adapter ratio]*((UITextView *)subview).font.pointSize];
//        }
        if (subview.subviews.count>0&&![subview isKindOfClass:[UIButton class]]) {
            [Adapter adapteFrameForNavaSubView:subview];
        }
    }
}
@end